import random



class CodeGenerator(object):
    """
    条码生成器
    """
    SEED_NUMBER_STR = "0123456789"
    SEED_LOW_LETTER_STR = "abcdefghijklmnopqrstuvwxyz"
    SEED_CAP_LETTER_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    @staticmethod
    def security_code(length: int):
        """
        按长度返回防伪码
        :param length:
        :return:
        """
        code_str = ""
        for i in range(0, length):
            code_str += str(random.choice(CodeGenerator.SEED_NUMBER_STR))

        return code_str

    @staticmethod
    def barcode_generation(barcode_info: str, path=None):
        """
        生成条形码
        :param barcode_info:
        :param path:
        :return:
        """
        from pystrich.ean13 import EAN13Encoder
        barcode = EAN13Encoder(barcode_info)
        barcode.save(barcode_info + ".png")

    @staticmethod
    def qrcode_generation(qrcode_info: str, path=None):
        """
        生成二维码
        :param qrcode_info:
        :param path:
        :return:
        """
        import qrcode
        encode = qrcode.make(qrcode_info)
        encode.save(qrcode_info + ".png")


if __name__ == '__main__':
    code_generator = CodeGenerator
    print(code_generator.security_code(5))
    print(code_generator.qrcode_generation("4577545453434"))
    print("\033[显示方式;前景色;背景色m")
    print("\033[1;30;46m--------------------------------")
    print("   1    2   3   4  5  6  7  8  9")
